package com.gzz.orchid.common.boot.mybatis.lambda;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author higmd
 */
public class QueryWarpper<T> {
    public Class<T> getGenericType() {
        Type type = getClass().getGenericSuperclass();
        ParameterizedType parameterizedType = (ParameterizedType) type;
        Type[] types = parameterizedType.getActualTypeArguments();
        if (types.length > 0){
            @SuppressWarnings("unchecked")
            Class<T> clazz = (Class<T>) types[0];
            return clazz;
        }

        throw  new IllegalStateException("无法获到泛型");
    }

    public static <T> QueryWarpper<T> builder() {
        return new QueryWarpper<T>(){};
    }

    public static void main(String[] args) {
        // 注意：这里用大括号{}, 是实例化匿名子类
//        var genericClass = new QueryWarpper<SysInfo>(){};
//        System.out.println(genericClass.getGenericType());
        Object sysInfo =null;
        sysInfo = new SysInfo();
        var genericClass = QueryWarpper.<SysInfo>builder();
        var clazz = genericClass.getGenericType();
        System.out.println(clazz);

        // System.out.println(sysInfo.getClass().getGenericSuperclass().getClass().getGenericInterfaces());
        System.out.println(sysInfo
                .getClass()
                .getGenericSuperclass()
                .getClass()
                .getGenericInterfaces()[0]
                .getTypeName()
        );
    }
}
